package com.bigdata.spark.core.framework.service

import com.bigdata.spark.core.framework.common.TService
import com.bigdata.spark.core.framework.dao.WordCountDao
import org.apache.spark.rdd.RDD

class WordCountService extends TService{
  private val wordCountDao = new WordCountDao()

  //数据分析
  def dataAnalysis()= {
    //1.读取文件，获取一行杨数据
    // 数据操作放到Dao层进行
    val lines = wordCountDao.readFile("datas/word.txt")

    //service 层进行数据逻辑处理
    val words:RDD[String] = lines.flatMap(_.split(" "))

    val wordToOne = words.map(word => (word, 1))

    val wordToSum:RDD[(String, Int)] = wordToOne.reduceByKey(_+_)
    val array:Array[(String, Int)] = wordToSum.collect()
    array
  }
}
